<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>系统用户管理</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css" >
	<link rel="stylesheet" type="text/css" href="/static/m.css" >
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/color.css" >
	<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
	<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
	<script src="/static/init.js"></script>
	<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
	<script src="/static/searchEdit.js"></script>
</head>
<body>
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >加载中,请稍候...</div></div>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center'" >
		<table id="gridList" ></table>
	</div>
</div>
<div id="searchbar">
<div class="maction">
		<a href="javascript:void(0)" id="btn1" class="easyui-linkbutton" data-options="">绑定登录账号</a>
		<a href="javascript:void(0)" id="authButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-user-tag mbutton'">角色设置</a>
</div>
<form id="searchForm" >
	ID:<input id="search-id" name="id" class="easyui-textbox" >
	昵称:<input id="search-nickname" name="nickname" class="easyui-textbox" >
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" >查询</a>
</form>
</div>
<div id="dialog_1" >
	<div class="easyui-panel" data-options="fit:true,border:false" style="width:100%;">
		<form id="form-1"  data-options="novalidate:true" class="easyui-form container">
		      	<div style="margin-bottom:20px">
					<input class="easyui-textbox" name="auth_id" style="width:100%" data-options="label:'登录账号ID',required:true">
				</div>
		</form>
		<div style="text-align:center;padding:5px 0">
			<a href="javascript:void(0)" onclick="javascript:save()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
			<a href="javascript:void(0)" onclick="javascript:cancel()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-times mbutton'">取消</a>
		</div>
	</div>
</div>
<div id="rolePanel" >
		<div class="easyui-layout" data-options="fit:true,border:false"  style="height:100%;width:100%;">
			<div data-options="region:'center',border:false" style="height:100%;width:100%;">
				<div data-options="fit:true,border:false" class="easyui-panel" title="" style="height:100%;width:100%;">
					<div id="roledatalist" title="" style="width:100%;height:90%" >
					</div>
				</div>
			</div>
			<div data-options="region:'south',border:false" style="text-align:center;height:55px;width:100%;padding-top:10px;">
				<a href="javascript:void(0)" onclick="javascript:saveRole()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
				<a href="javascript:void(0)" onclick="javascript:closePanel()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-times mbutton'">取消</a>
			</div>
		</div>
	</div>
<script>
function cancel(){
	$('#dialog_1').dialog("close");
}
function save(){
	if($("#form-1").form('enableValidation').form('validate')){
		var formObject=$("#form-1").serializeObject();
		let row=grid1.getSelectedRow();
		formObject.user_id=row.id;
		$.post("/authenticated/user/bindLogin",formObject,function(result){
			if(result.success){
				$.messager.alert("提示", "绑定成功！");
				grid1.load();
				$('#dialog_1').dialog("close");
			}else{
				$.messager.alert("提示", "绑定失败！\n"+result.message);
			}
		});
	}
}
var options={
		page_id:204,
		grid_id:"gridList",
		sqlname:"grid_204_sys_user",
		showCheckbox:false,
		rownumbers:false,
		column_formatter:{
			
		},
		searchParamOperator:{
			nickname:"contain"
		}
	};
	//document ready
	$(function(){
		grid1=new uniontrip.datagrid.searchEdit(options);
		
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		$('#addButton').bind('click', addRow);//新增行绑定事件
		$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
		$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		$('#authButton').bind('click', menuAuth);//角色设置绑定事件
	   //信息变更提示
	    //初始化搜索框
	    initsearch();
	    $('#btn1').bind('click',bindLogin);
	    dialogHeight=windowHeight*0.6;
		$('#dialog_1').dialog({
			title:"绑定登录账号",
			cls:"miframePanel",
			width:'400px',
			height:dialogHeight,
			modal:true,
			closed:true,
			maximizable:true,
			onClose:function(){
				//grid1.load();
			},
			/* buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					alert('ok');
				}
			},{
				text:'取消',
				handler:function(){
					alert('cancel');;
				}
			}] */
		});
		$('#rolePanel').dialog({
			title:"角色设置",
			cls:"miframePanel",
			width:'300px',
			height:dialogHeight,
			modal:true,
			closed:true,
			maximizable:true,
			onClose:function(){
				//grid1.load();
			},
			/* buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					alert('ok');
				}
			},{
				text:'取消',
				handler:function(){
					alert('cancel');;
				}
			}] */
		});
	});

	
	/**
     * 角色设置
     */
    function menuAuth(){
    	var selectRows=grid1.grid.datagrid('getSelections');
		if(selectRows.length>0){
			selectRowid=selectRows[0].id;
			var roledata;
			$.ajax({
				type: "post",
				contentType:"application/json",
	    		url: "/authenticated/ajax/select_user_role_br_ulid",
	    		data:JSON.stringify({user_id:selectRowid}),
	    		dataType:"json",
	    		success: function(result){
	    			if(result.success){
	    				roledata=result.data;
	    				$('#roledatalist').datalist({
	    					checkbox: true,
	    					singleSelect:false,
	    					valueField:'id',
	    					textField:'role_name',
	    					data:roledata
	    				});
	    				$.each(roledata,function(i,v){
	    					if(v.checked=="true"){
	    						$('#roledatalist').datalist("checkRow",i);
	    					}
	    				});
	    			}else{
	    				$.messager.alert("提示", "查询角色信息失败！<br>"+result.message);
	    			}
	    		},
	    		error: function(){
	    			$.messager.alert("提示", "请求失败！");
	    		}
	    	});
			$('#rolePanel').dialog('open');
		}else{
			info('请选择一条数据！');
		}
    }
    function saveRole(){
    	var checkedRows=$('#roledatalist').datalist('getChecked');
    	var checkArray=new Array();
    	$.each(checkedRows,function(i,v){
    		checkArray.push(v.id);
		});
    	
    	var param={"user_id":selectRowid,"roleids":checkArray};
    	$.ajax({
    		type: "post",
    		contentType:"application/json",
    		url: "/authenticated/userrole",
    		data:JSON.stringify(param),
    		dataType:"json",
    		success: function(result){
    			if(result.success){
    				$.messager.alert("提示", "授权成功！");
    				closePanel();
    			}else{
    				$.messager.alert("提示", "授权失败！<br>"+result.message);
    			}
    		},
    		error: function(){
    			$.messager.alert("提示", "请求失败！");
    		}
    	});
    	
    	selectRowid=undefined;
    }
    function closePanel(){
		$('#rolePanel').dialog('close');
	}
	/**
	 * 新增一行
	 */
	function addRow(){
		var newRowData={id:guid()};//初始化行数据
		grid1.grid.datagrid('append',newRowData);	
	}
	function bindLogin(){
		gridSelectRow(grid1.grid,function(row){
			if(row.login_username){
				info("用户已绑定账号了");
			}else{
				$('#dialog_1').dialog('setTitle','绑定登录账号').dialog('open');
			}
			
		});
	}
	function onDeleteRow(){
		gridConfirm(grid1.grid,"是否确认删除",deleteRow);
	}
	function deleteRow(row){
		$.post("/authenticated/xx/delete",JSON.stringify({"id":row.id}),function(result){
			if(result.status==200){
				$.messager.alert("提示", "删除成功！");
				grid1.load();
			}else{
				$.messager.alert("提示", "删除失败！<br>"+result.message);
			}
		});
	}


	/**
	 * 初始化搜索条件
	 */
	function initsearch(){
		/*$('#search-product_class_id').combotree({
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-product_class_id').combotree('clear');
				}
			}],
		    data:grid1.combotreeDatas.product_class_id
		});
		//初始化combobox例子
		$('#search-status').combobox({
			panelHeight:'auto',
			editable:false,
			valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(e){
					$(e.data.target).combobox('clear');
				}
			}],
		    data:grid1.comboboxDatas.status
		});*/
	}
</script>
</body>
</html>